import 'package:cat_eye/base/base_chang_notifier.dart';
import 'package:cat_eye/base/base_view_model.dart';
import 'package:cat_eye/bean/sq_lite_bean.dart';
import 'package:cat_eye/sqflite/sqLite_manager.dart';
import 'package:cat_eye/util/loading_state_widget_util.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

/*
* @Package: view_model
* @ClassName: my_attention_view_model
* @Author: szj
* @CreateDate: 8/3/21 2:40 PM
*/
class MyAttentionViewModel extends BaseViewModel {
  List<SqLiteBean> list = [];

  @override
  void refresh() async {
    if (this.list.length > 0) {
      this.list.clear();
    }

    type = LoadingWidget.DONG;
    refreshController.refreshCompleted();
    refreshController.footerMode.value = LoadStatus.canLoading;
    var list = await SQLiteManager.getInstance().queryAllData();

    //倒序
    this.list.addAll(list.reversed);
    notifyListeners();
  }

  void delete(int id, String bodyImageUrl) {
    SQLiteManager.getInstance().delete(bodyImageUrl);
    list.removeAt(id);
    notifyListeners();
  }

  //允许下拉
  @override
  bool get isRefresh => true;

  //  下面是网络请求的，不要这个
  @override
  // TODO: implement httpUrl
  String get httpUrl => throw UnimplementedError();

  @override
  void successJsonData(json) {
    // TODO: implement successJsonData
  }
}
